package org.openstock.impl.def.charting.ui.swing.presenter.delegate.builder;

import org.openstock.api.charting.presenter.delegate.builder.ChartBuilder;
import org.openstock.impl.def.charting.ui.swing.model.DefaultSwingStockChart;
import org.openstock.impl.def.core.factory.Factory;

public class DefaultSwingStockChartBuilder implements
		ChartBuilder<DefaultSwingStockChart> {

	private DefaultSwingAxisBuilder defaultSwingAxisBuilder;
	private DefaultGridBuilder defaultGridBuilder;
	private DefaultCrosshairBuilder defaultCrosshairBuilder;
	
	public DefaultSwingStockChartBuilder() {
		defaultSwingAxisBuilder = Factory.getSingleton(DefaultSwingAxisBuilder.class);
		defaultGridBuilder = Factory.getSingleton(DefaultGridBuilder.class);
		defaultCrosshairBuilder = Factory.getSingleton(DefaultCrosshairBuilder.class);
	}
	
	@Override
	public DefaultSwingStockChart build() {
		DefaultSwingStockChart chart = buildInternal();
		chart.setVerticalAxis(defaultSwingAxisBuilder.build());
		chart.setHorizontalAxis(defaultSwingAxisBuilder.build());
		chart.setGrid(defaultGridBuilder.build());
		chart.setCrosshair(defaultCrosshairBuilder.build());
		return chart;
	}
	
	private DefaultSwingStockChart buildInternal(){
		return Factory.getPrototype(DefaultSwingStockChart.class);
	}

}
